package pkg;

import java.io.*;
import java.util.Random;

import javax.servlet.*;
import javax.servlet.http.*;

import oracle.sql.DATE;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.struts.action.*;
import org.apache.tomcat.jni.Time;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import HibernateBeans.CustomerDetails;

public class CustomerDetailsAction extends Action {
	public static Serializable id;
	public static Transaction tx;
	public static Session session;

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		SessionFactory sessionFactory=new Configuration().configure().buildSessionFactory();
		session=sessionFactory.getCurrentSession();
		tx=session.beginTransaction();


		//DynaActionForm myform = (DynaActionForm) form;
		//CustomerDetails cd = new CustomerDetails();
		//PropertyUtils.copyProperties(myform, cd);
		System.out.println((HibernateBeans.CustomerDetails)form);
        //((HibernateBeans.CustomerDetails)form).setUser_id("C0" + Math.abs((new Random(new java.util.Date().getTime()).nextInt(999999999))));
        id = session.save(form);

		return mapping.findForward("ProductSelection");

	}
}